package com.cssw.fyzb.core.dao.live;



import com.cssw.fyzb.core.model.dodb.CmfLiveMute;
import com.cssw.fyzb.core.model.dodb.CmfLiveReport;
import com.cssw.fyzb.core.model.dodb.SysFunc;
import com.ydn.dbframe.plugin.activerecord.Page;
import com.ydn.dbframe.plugin.activerecord.parse.SqlParse;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: yangyiqun
 * @Date: 2020/10/10 15:10
 */
@Repository
public class LiveReportDaoImpl implements LiveReportDao {
    /**
     * 查询菜单列表
     *
     * @param page
     * @param limit
     * @param param
     * @return
     */
    public Page<CmfLiveReport> list(int page, int limit, Map param) {
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL("select * from cmf_live_report");
        sqlParse.addSQL(" order by report_id desc ");
        return CmfLiveReport.dao.paginate(page, limit, sqlParse);
    }



    public CmfLiveReport findOne(Long reportId){
        return CmfLiveReport.dao.findById(reportId);
    };

    public  void save(Long reportId, String state){
        CmfLiveReport cmfLiveReport = new CmfLiveReport();
        cmfLiveReport.setReportId(reportId);
        cmfLiveReport.setStatus(state);
        cmfLiveReport.setUpdateTime(new Date());
        cmfLiveReport.update();
    }

    @Override
    public Long addLiveReport(Long liveId, Long fromUserId, Long toUserId, String content) {
        CmfLiveReport cmfLiveReport = new CmfLiveReport();
        cmfLiveReport.setLiveId(liveId);
        cmfLiveReport.setFromUserId(fromUserId);
        cmfLiveReport.setToUserId(toUserId);
        cmfLiveReport.setContent(content);
        cmfLiveReport.setStatus("1");
        cmfLiveReport.setCreateTime(new Date());
        cmfLiveReport.save();
        return cmfLiveReport.getReportId();
    }

    @Override
    public void removeLiveReportById(Long id) {
        CmfLiveReport cmfLiveReport = CmfLiveReport.dao.findById(id);
        if(cmfLiveReport!=null){
            cmfLiveReport.delete();
        }
    }

    @Override
    public Page<CmfLiveReport> listLiveReport(Long liveId, Integer pageNumber, Integer pageSize) {
        Map<String,Object> params = new HashMap<>();
        params.put("liveId", liveId);
        SqlParse sqlParse = new SqlParse(params);
        sqlParse.addSQL("select * from cmf_live_report where live_id=:liveId");
        return CmfLiveReport.dao.paginate(pageNumber, pageSize, sqlParse);
    }
}
